<template>
  <!-- 导入表 -->
  <lam-dialog title="导入表" :visible.sync="visible" width="800px" top="5vh" append-to-body @close="visible = false">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="表名称" prop="tableNameKey">
        <el-input v-model="queryParams.tableNameKey" placeholder="请输入表名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="表描述" prop="tableCommentKey">
        <el-input v-model="queryParams.tableCommentKey" placeholder="请输入表描述" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search"  @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 列表区域 -->
    <selected-info :count="selectedRows.length" :onClearSelected="onClearSelected" />
    <el-table @row-click="clickRow" ref="dataTable" :data="dataList" stripe border @selection-change="onSelectChange" height="500px">
      <el-table-column align="center"  type="selection" width="55"></el-table-column>
      <el-table-column align="center"  prop="tableName" label="表名称" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column align="center"  prop="tableComment" label="表描述" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column align="center"  prop="createTime" label="创建时间"></el-table-column>
      <el-table-column align="center"  prop="updateTime" label="修改时间"></el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleImportTable">确 定</el-button>
      <el-button @click="visible = false">取 消</el-button>
    </div>
  </lam-dialog>
</template>

<script>
  import { IndexListMixin } from '@/components/mixins/IndexListMixin';
  import { httpGet, httpPost } from "@/api";

export default {
  name: "ImportTable",
  mixins:[IndexListMixin],
  data() {
    return {
      // 遮罩层
      visible: false,
      useOrder: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tableName: undefined,
        tableComment: undefined
      },
      url:{
        list: '/tool/gen/db/list',
        importTable: '/tool/gen/importTable',
      }
    };
  },
  methods: {

    // 显示弹框
    show() {
      this.getList();
      this.visible = true;
    },

    clickRow(row) {
      this.$refs.dataTable.toggleRowSelection(row);
    },

    // 查询表数据
    getList() {
      this.loadData(this.url.list);
    },

    /** 导入按钮操作 */
    handleImportTable() {
      let tableName = this.selectedRows.map(item => item.tableName).join(",");
      httpPost(this.url.importTable, { tableName }).then(res => {
        this.msgSuccess(res.msg);
	      this.visible = false;
	      this.$emit("ok");
      })
    }

  }
};
</script>
